using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_PlaceList : PagedControl
{
    PlaceDAO daoPlace = new PlaceDAO();
    #region properties
    public override string RequestString
    {
        get
        {
            if (Request["search"] != null) return "Default.aspx?ctrl=place_list&search=" + Request["search"] + "&page=";
            return "Default.aspx?ctrl=place_list&page=";
        }
    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        ActiveAccording = "place";
        p = Request["page"];
        totals = 0;
        currentPage = GetPageNumber(p);
        LoadData();        
    }
    public void LoadData()
    {
        if (Request["search"] == "" || Request["search"] == null)
        {
            dgrPlace.DataSource = daoPlace.GetPlaces(currentPage, pageSize, ref totals,ServiceObject.Both);
        }
        else
        {
            dgrPlace.DataSource = daoPlace.GetPlacesExt(currentPage, pageSize, ref totals, "%" + Request["search"] + "%", false,ServiceObject.Both);

        }
        dgrPlace.DataBind();
        lblPaging.Text = GetPageGrid(totals, pageSize, currentPage);
    }
    protected void lnkDelete_Click(object sender, EventArgs e)
    {
        int count = 0;
        bool rs = true;
        foreach (GridViewRow row in dgrPlace.Rows)
        {
            bool check = ((CheckBox)(row.FindControl("chkChoice"))).Checked;
            if (check)
            {
                ((CheckBox)(row.FindControl("chkChoice"))).Checked = false;
                count++;
                int id = int.Parse(dgrPlace.DataKeys[row.RowIndex].Value.ToString());
                if (daoPlace.Delete(id) <= 0)
                {
                    rs = false;
                    break;
                }
            }
        }
        if (count == 0) ShowMessage("Please specify item to delete");
        else if (rs) ShowMessage("Selected items are deleted successfully");
        else ShowMessage("Error occured. Some items may not be deleted");
        LoadData();
    }
}
